﻿
#include "pincfg.h"
#include "uuid_verify.h"
#include "dataproc.h"
#include "sys_init.h"
#include "common.h"

//密码空间2KB
//#define FLASH_Unlock FLASH_Unlock
//#define FLASH_Lock FLASH_Lock
//#define FLASH_ProgramWord FLASH_ProgramWord
#define FLASH_Erase FLASH_ErasePage

/*****************************************************************************/ /*!
* @brief   jiami.   实际代码大约200-300字节，开优化
*					可将代码对齐在擦除扇区边界
*					直接擦除加密后直接擦除即可，无需填充操作，0xFFFF执行和NOP同
* @param   none		
* @return  none
* @ Pass/ Fail criteria: none
*****************************************************************************/
void uidvf_handle(void) @ ".jm_rom"
{
	int group;
    uidvf_check_alloc();

	uidvf_enc_rom_addr_make(0, 0);
	
    FLASH_Unlock();		//解锁flash
    FLASH_Erase(uidvf.addr);
	
	for(group=0; group < UIDVF_CODE_LEN / UIDVF_BLOCK_SIZE; group++)
	{
		uidvf_enc_gen(group);
		
		uidvf_enc_rom_addr_make(group, 0);
		
		FLASH_ProgramWord(uidvf.addr, uidvf.out[0]);
		FLASH_ProgramWord(uidvf.addr + 4, uidvf.out[1]);
		FLASH_ProgramWord(uidvf.addr + 8, uidvf.out[2]);
		FLASH_ProgramWord(uidvf.addr + 12, uidvf.out[3]);
	}
    
    FLASH_Lock();
	
	uidvf_free();
	
	dbg_u8_print("jiami: \n", (void *)UIDVF_ENC_ADDR, UIDVF_CODE_LEN, 32);
	

}
